﻿namespace Sidvall.LogManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogScopeItemCategory : global::Sidvall.LogManager.UI.Entities.Core.BusinessBase, global::Sidvall.LogManager.Data.ILogScopeItemCategory
    {
        #region Business Members

        #region Category

        private string _Category = string.Empty;
        partial void OnBeforeCategoryPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeCategoryPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterCategoryPropertyChanged();
        public string Category
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Category);
                OnBeforeCategoryPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Category);
                OnBeforeCategoryPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Category", eventData.Value, true, true, true);
                    OnAfterCategoryPropertyChanged();
                }
            }
        }

        #endregion
        #region LogScopeItemId

        private long _LogScopeItemId = 0L;
        partial void OnBeforeLogScopeItemIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeLogScopeItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterLogScopeItemIdPropertyChanged();
        public long LogScopeItemId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_LogScopeItemId);
                OnBeforeLogScopeItemIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _LogScopeItemId);
                OnBeforeLogScopeItemIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LogScopeItemId", eventData.Value, true, true, true);
                    OnAfterLogScopeItemIdPropertyChanged();
                }
            }
        }

        #endregion
        #region LogScopeItem

        private LogScopeItem _LogScopeItem;
        partial void OnBeforeLogScopeItemPropertyChanged(Sidvall.Business.PropertyChangeEventData<LogScopeItem> eventData);
        partial void OnAfterLogScopeItemPropertyChanged();
        public LogScopeItem LogScopeItem
        {
            get
            {
                return _LogScopeItem;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<LogScopeItem> eventData = new Sidvall.Business.PropertyChangeEventData<LogScopeItem>(value, _LogScopeItem);
                OnBeforeLogScopeItemPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("LogScopeItem", eventData.Value, true, true, false);
                    OnAfterLogScopeItemPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadLogScopeItemAsync

        public async System.Threading.Tasks.Task<LogScopeItem> LoadLogScopeItemAsync()
        {
            return await LoadLogScopeItemAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> LoadLogScopeItemAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeItemField, global::Sidvall.LogManager.Data.Relations.LogScopeItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.LoadLogScopeItemAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.LogScopeItem;
        }
        public LogScopeItem LoadLogScopeItem(LogScopeItem item)
        {
            LoadInstanceField("LogScopeItem", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public LogScopeItemCategory Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public LogScopeItemCategory Copy()
        {
            return Copy(null);
        }
        public LogScopeItemCategory Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new LogScopeItemCategory();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogScopeItemCategory item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogScopeItemCategory item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(LogScopeItemCategory destination, global::Sidvall.LogManager.Data.ILogScopeItemCategory source, Sidvall.Data.CopySettings copySettings);
        private void Import(LogScopeItemCategory destination, global::Sidvall.LogManager.Data.ILogScopeItemCategory source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(LogScopeItemCategory destination, LogScopeItemCategory source, Sidvall.Data.CopySettings copySettings);
        private void Import(LogScopeItemCategory destination, LogScopeItemCategory source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.LogManager.Data.ILogScopeItemCategory, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync()
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.LogManager.UI.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.UI.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Initialize(this, settings);
        }

        #endregion
        
        #region ILogScopeItemCategory Members

        string global::Sidvall.LogManager.Data.ILogScopeItemCategory.Category
        {
            get
            {
                return this._Category;
            }
            set
            {
                this._Category = value;
            }
        }
        long global::Sidvall.LogManager.Data.ILogScopeItemCategory.LogScopeItemId
        {
            get
            {
                return this._LogScopeItemId;
            }
            set
            {
                this._LogScopeItemId = value;
            }
        }
        global::Sidvall.LogManager.Data.ILogScopeItem global::Sidvall.LogManager.Data.ILogScopeItemCategory.LogScopeItem
        {
            get
            {
                return this._LogScopeItem;
            }
            set
            {
                UpdateChildProperty(this._LogScopeItem, value);
                this._LogScopeItem = value as LogScopeItem;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public LogScopeItemCategory()
        {
        }

        public LogScopeItemCategory(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}